#ifndef GBTRACKBAR_H
#define GBTRACKBAR_H

#include "GBWidget.h"

class GBTrackBar : public GBWidget
{
private:
	int m_trackerMeshID;

	float m_trackerPosX;
	float m_min;
	float m_max;

	Color m_trackerColor;
	vec2 m_trackerSize;
	vec2 m_lineSize;

public:
	GBTrackBar();
	GBTrackBar(const GBTrackBar& ref) { Copy(&ref); }
	~GBTrackBar();

	void Render();
	void Update(const float fTimeStep);
	void Copy(const GBWidget* pRef);

	Color GetTrackerColor() const { return m_trackerColor; }
	vec2 GetTrackerSize() const { return m_trackerSize; }
	vec2 GetLineSize() const { return m_lineSize; }
	float GetMaxValue() const { return m_max; }
	float GetMinValue() const { return m_min; }
	vec2 GetTrackerPosition() const { return vec2(m_trackerPosX, m_local.wAxis().Y()); }
	int GetTrackerMeshID() const { return m_trackerMeshID; }

	void SetTrackerColor(Color color) { m_trackerColor = color; }
	void SetLineSize(vec2 size) { m_lineSize = size; }
	void SetTrackerSize(vec2 size) { m_trackerSize = size; }
	void SetMaxValue(float max) { m_max = max; }
	void SetMinValue(float min) { m_min = min; }
	void SetTrackerPosition(float posX) { m_trackerPosX = posX; }
	void SetTrackerMeshID(int meshID) { m_trackerMeshID = meshID; }

	WidgetType Type() const { return WIDGET_TYPE_TRACK_BAR; }

	float GetCurrentValue()
	{
		float percent = GetPercentile();
		float current = 0.0f;

		// Check for negatives and halves to make it negative
		vec2 min = vec2(m_min, 0.0f);
		vec2 max = vec2(m_max, 0.0f);

		current = (Interpolate(min, max, percent).X());

		return current;
	}

	void SetPercentile(float percent)
	{
		Clamp(0.0f, percent, 1.0f);

		vec2 lineBegin = vec2(m_local.wAxis().X(), 0.0f);
		vec2 lineEnd = vec2(m_local.wAxis().X() + m_lineSize.X(), 0.0f);

		m_trackerPosX = Interpolate(lineBegin, lineEnd, percent).X();
	}

	// Returns a percentile between 0% - 100% (0.0f - 1.0f)
	inline float GetPercentile()
	{
		float lineCurr = (m_trackerPosX - m_local.wAxis().X());	// Current - Begin

		return (lineCurr / m_lineSize.X());
	}
};

#endif